from typing import List, Optional

__all__ = ['Player']


class Player:
    def __init__(self, name: Optional[str] = None):
        self.name: Optional[str] = name
        self.units: list = []
        self.buildings: list = []
        self.inventories: List[List[str]] = []
        self.tech: List[str] = []
        self.color: Optional[str] = None

    def add_unit(self, unit):
        self.units.append(unit)
        self.inventories.append(unit.inventory)
        unit.owner = self

    def add_building(self, building):
        self.buildings.append(building)
        self.inventories.append(building.inventory)
        building.owner = self

    @property
    def inventory(self):
        return sum(self.inventories, [])
